package com.qingcheng.consumer;

import com.alibaba.fastjson.JSON;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import java.util.Map;

/**
 * @Author: LDeng
 * @Date: 2020-05-27 17:31
 */
public class SmsMessageConsumer implements MessageListener {

    //注入SmsUtil对象
    @Autowired
    private SmsUtil smsUtil;

    @Value("${templateCode}")
    private String templateCode;
    @Value("${templateParam}")
    private String templateParam;

    public void onMessage(Message message) {
        String jsongString = new String(message.getBody());
        Map<String,String> map = JSON.parseObject(jsongString, Map.class);
        String phone = map.get("phone");//手机号
        String code = map.get("code");//验证码
        System.out.println("==============》手机号："+phone);
        System.out.println("==============》验证码："+code);

        //调用阿里云通信发送短信
        smsUtil.sendSms(phone,templateCode,templateParam.replace("[value]",code));// 将[value]替换成code

    }
}
